<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.title" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />


        <!--
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        
<el-date-picker
          v-model="query.createTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="createTimeStart"
          end-placeholder="createTimeEnd"
        />
        <el-date-picker
          v-model="query.updateTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="updateTimeStart"
          end-placeholder="updateTimeEnd"
        />

        -->
        
        
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
        <!--
          <el-form-item label="主键id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="编辑时间">
            <el-date-picker v-model="form.updateTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加时间">
            <el-date-picker v-model="form.createTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="删除(0存/1删)">
                未设置字典，请手动设置 Radio
          </el-form-item>

        -->
          <el-form-item label="标题">
            <el-input v-model="form.title" style="width: 370px;" />
          </el-form-item>

        <!--
          <el-form-item label="类型">
            <el-input v-model="form.type" style="width: 370px;" />
          </el-form-item>
        -->
        <el-form-item label="类型">
            <el-radio-group v-model="form.type" style="width: 178px">
                  <el-radio-button label="banner">轮播图</el-radio-button>
                  <el-radio-button label="head">导航栏</el-radio-button>
            </el-radio-group>
        </el-form-item>



          <el-form-item label="图片">
              <MaterialList
                      v-model="picUrlArr"
                      style="width: 915px;"
                      type="image"
                      :num="1"
                      :width="150"
                      :height="150"
              />
          </el-form-item>
          <el-form-item label="描述">
            <el-input :rows="3" v-model="form.msg" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="路由">
            <el-input v-model="form.outUrl" style="width: 370px;" />
          </el-form-item>
        
        
          <el-form-item label="权重">
            <el-input v-model="form.weight" style="width: 370px;" />
          </el-form-item>

          
          
          <el-form-item label="状态">
                <!--  <el-radio-group v-model="form.is_open" style="width: 178px">  -->
                <el-radio-group v-model="form.isOpen" style="width: 178px">
                  <el-radio :label="1">显示</el-radio>
                  <el-radio :label="0">隐藏</el-radio>
                </el-radio-group>
          </el-form-item>
          
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('title')" prop="title" label="标题" />
        <!--<el-table-column v-if="columns.visible('type')" prop="type" label="类型" />-->


<el-table-column v-if="columns.visible('type')" label="类型" align="center" prop="isOpen">
              <template slot-scope="scope">
                <div>
                  <div v-if="scope.row.type == 'banner'" :type="''">轮播图</div>

                  <div v-else :type=" 'info' ">导航栏</div>
                </div>

              </template>
      </el-table-column>


          <el-table-column v-if="columns.visible('picUrl')" prop="picUrl" label="图片">
            <template slot-scope="scope">
              <a :href="scope.row.picUrl" style="color: #42b983" target="_blank">
                <img :src="scope.row.picUrl" alt="点击打开" class="table-img" />
              </a>
            </template>
          </el-table-column>
        <el-table-column v-if="columns.visible('msg')" prop="msg" label="描述" />

        
        <!--
        <el-table-column v-if="columns.visible('isOpen')" prop="isOpen" label="是否开启(0关/1开)" />
        
        <el-table-column v-if="columns.visible('isOpen')" prop="isOpen" label="状态" />
        -->


      <el-table-column v-if="columns.visible('isOpen')" label="状态" align="center" prop="isOpen">
              <template slot-scope="scope">
                <div>
                  <el-tag v-if="scope.row.isOpen === 1" :type="''">显示</el-tag>
                  <el-tag v-else :type=" 'info' ">隐藏</el-tag>
                </div>
              </template>
      </el-table-column>

        
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="添加时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>


        <!--
        <el-table-column v-if="columns.visible('outUrl')" prop="outUrl" label="外部跳转地址" />
        <el-table-column v-if="columns.visible('withUrl')" prop="withUrl" label="内部跳转地址" />
        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="编辑时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('weight')" prop="weight" label="权重(越高越好)" />
        <el-table-column v-if="columns.visible('isDel')" prop="isDel" label="删除(0存/1删)" />
        -->

        <el-table-column v-permission="['admin','yxStoreConfiguration:edit','yxStoreConfiguration:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudYxStoreConfiguration from '@/api/yxStoreConfiguration'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '', url: 'api/yxStoreConfiguration', sort: 'id,desc', crudMethod: { ...crudYxStoreConfiguration }})
const defaultForm = { id: null, title: null, type: null, picUrl: null, msg: null, outUrl: null, withUrl: null, isOpen: null, createTime: null, updateTime: null, weight: null, isDel: null }
export default {
  name: 'YxStoreConfiguration',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      picUrlArr:[],
      permission: {
        add: ['admin', 'yxStoreConfiguration:add'],
        edit: ['admin', 'yxStoreConfiguration:edit'],
        del: ['admin', 'yxStoreConfiguration:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: '主键id' },
        { key: 'title', display_name: '标题' },
        { key: 'type', display_name: '类型' },
        { key: 'picUrl', display_name: '图片地址' },
        { key: 'msg', display_name: '文字描述' },
        { key: 'outUrl', display_name: '外部跳转地址' },
        { key: 'withUrl', display_name: '内部跳转地址' },
        { key: 'isOpen', display_name: '是否开启(0关/1开)' },
        { key: 'weight', display_name: '权重(越高越好)' },
        { key: 'isDel', display_name: '删除(0存/1删)' }
      ]
    }
  },
  watch: {
    "picUrlArr":function(val) {
      if (val) {
        this.form.picUrl = val.join(",");
      }
    },
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.id
        delete this.crud.params.title
        delete this.crud.params.type
        delete this.crud.params.picUrl
        delete this.crud.params.msg
        delete this.crud.params.outUrl
        delete this.crud.params.withUrl
        delete this.crud.params.isOpen
        delete this.crud.params.weight
        delete this.crud.params.isDel
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      if (form.picUrl && form.id) {
        this.picUrlArr = form.picUrl.split(",");
      }else{
        this.picUrlArr=[]
      }
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
